/*
* Copyright (c)  2017, ueboot.com
* All rights reserved.
* 2017-10-10 17:19:43
*/
package com.ueboot.weishop.service.activity.impl;

import com.ueboot.weishop.entity.activity.ActivityAttrEntity;
import com.ueboot.core.repository.BaseRepository;
import com.ueboot.weishop.repository.activity.ActivityAttrRepository;
import com.ueboot.core.service.impl.BaseServiceImpl;
import com.ueboot.weishop.service.activity.ActivityAttrService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by yangkui  on 2017-10-10 17:19:43.
 *
 * @since 2.0 by autocode
 */
@Slf4j
@Service
public class ActivityAttrServiceImpl extends BaseServiceImpl<ActivityAttrEntity> implements ActivityAttrService {

    @Autowired
    private ActivityAttrRepository activityAttrRepository;

    @Override
    protected BaseRepository getBaseRepository() {
         return activityAttrRepository;
    }

	@Override
	@Cacheable(key = "'weishop:activityAttr:'+#activitySn + ':'", cacheNames = "activityAttr")
	public List<ActivityAttrEntity> findBySn(String activitySn) {
		return activityAttrRepository.findBySn(activitySn);
	}


    @Override
    public List<ActivityAttrEntity> findBySnNoCache(String activitySn) {
        return activityAttrRepository.findBySn(activitySn);
    }

	@Override
	@Cacheable(key = "'weishop:activityAttr:'+#activitySn + ':' + #keyName", cacheNames = "activityAttr")
	public ActivityAttrEntity findBySnAndKey(String activitySn, String keyName) {
		return activityAttrRepository.findOneBySnAndKeyName(activitySn, keyName);
	}

	@Override
	@CacheEvict(key = "'weishop:activityAttr:'+#sn+'*'", cacheNames = "activityAttr")
	public void save(String sn, List<ActivityAttrEntity> list) {
		for (ActivityAttrEntity attr : list) {
			activityAttrRepository.save(attr);
		}
	}
}
